package ioc14;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/5/17 11:22
 * Version:1.0-SNAPSHOT
 * Description:
 */
public class Test {

    public static void main(String[] args) throws ParseException {
//        ObjectFactory factory = new ObjectFactory();
//        SomeService someService = (SomeService) factory.getObject();
        ApplicationContext ac = new ClassPathXmlApplicationContext("ioc14/spring.xml");
        SomeService someService = (SomeService) ac.getBean("someService");
        SomeService someService2 = (SomeService) ac.getBean("someService");
        System.out.println(someService);
        System.out.println(someService2);
        someService.doSome();
        System.out.println("------------------");
        someService.doOther();


        // 练习:生成一个日期对象的过程
        // 要求:使用FactoryBean进行生产
        // 且生成的年月日的最终的值是交给Spring进行管理的
        // 即:Spring对年月日的值进行注入
//        String year = "2022";
//        String month = "05";
//        String day = "17";
//        Date date = new SimpleDateFormat("yyyy-MM-dd").parse(year+"-"+month+"-"+day);
        Date date = (Date) ac.getBean("date");
        System.out.println(date);
    }

}
